package com.cunshe.web.manage;

import com.cunshe.common.ResponseVO;
import com.cunshe.config.annotation.Login;
import com.cunshe.dao.HomeImageDao;
import com.cunshe.domain.HomeImage;
import com.cunshe.entity.vo.HomeImageInsertVO;
import com.cunshe.entity.vo.HomeImageUpdateVO;
import com.cunshe.service.HomeImageService;
import com.cunshe.web.BaseController;
import com.sunkee.commons.utils.ConvertUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 首页
 * @author xiao
 */
@Api(tags = "首页图片")
@Login
@RestController
@RequestMapping(value = "/manage/homeImage")
public class HomeImageController extends BaseController {

    @Autowired
    private HomeImageService homeImageService;

    /** 新增 */
    @ApiOperation(value = "新增")
    @PostMapping(value = "insert")
    public ResponseVO insert(@RequestBody HomeImageInsertVO vo) {
        HomeImage record = ConvertUtil.copyProperties(vo, HomeImage.class);
        homeImageService.insert(record);
        return ResponseVO.success();
    }

    /** 删除 */
    @ApiOperation(value = "删除")
    @PostMapping(value = "delete")
    public ResponseVO delete(@RequestParam("id") Long id) {
        homeImageService.delete(id);
        return ResponseVO.success();
    }

    /** 修改 */
    @ApiOperation(value = "修改")
    @PostMapping(value = "update")
    public ResponseVO update(@RequestBody HomeImageUpdateVO vo) {
        HomeImage record = ConvertUtil.copyProperties(vo, HomeImage.class);
        homeImageService.update(record);
        return ResponseVO.success();
    }

    /** 查询列表 */
    @ApiOperation(value = "查询列表")
    @PostMapping(value = "list")
    public ResponseVO<List<HomeImage>> list(@RequestBody(required = false) HomeImage record) {
        List<HomeImage> list = homeImageService.list(record);
        return ResponseVO.success(list);
    }

}